﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace PostProcessing
{
    public class Log
    {
        public Dictionary<string, string> regrasGenRealmenteUteis;
        public Dictionary<string, string> regrasGeneralizadas;
        public Dictionary<string, string> regrasGenConfBaixa;
        public Dictionary<string, string> regrasGenInuteis;
        public Dictionary<string, string> regrasGenEmLinha;

        public Log()
        {
            regrasGenRealmenteUteis = new Dictionary<string, string>();
            regrasGeneralizadas = new Dictionary<string, string>();
            regrasGenInuteis = new Dictionary<string,string>();
            regrasGenConfBaixa = new Dictionary<string,string>();
            regrasGenEmLinha = new Dictionary<string, string>();
        }

        public void contarGenUteis(List<Rule> regras)
        {
            foreach (Rule regra in regras)
            {
                if (regra.generalizada != null)
                    regrasGenRealmenteUteis.Add(regra.ToString(), regra.generalizada.ToString());
            }
        }

        public void salvarArquivo(string nomeArqLog)
        {
            StreamWriter streamWriter = new StreamWriter(nomeArqLog);

            streamWriter.WriteLine("Pré-Generalização Em Linha");
            streamWriter.WriteLine("//------------------------");
            streamWriter.WriteLine("");

            foreach (KeyValuePair<string, string> parRegras in regrasGenEmLinha)
            {
                streamWriter.WriteLine(parRegras.Key);
                streamWriter.WriteLine(parRegras.Value);
                streamWriter.WriteLine();
            }

            streamWriter.WriteLine("");
            streamWriter.WriteLine("");

            streamWriter.WriteLine("Regras Generalizadas");
            streamWriter.WriteLine("//------------------");
            streamWriter.WriteLine("");

            foreach (KeyValuePair<string, string> parRegras in regrasGeneralizadas)
            {
                streamWriter.WriteLine(parRegras.Key);
                streamWriter.WriteLine(parRegras.Value);
                streamWriter.WriteLine();
            }

            streamWriter.WriteLine("");
            streamWriter.WriteLine("");

            streamWriter.WriteLine("Regras Generalizadas Inuteis");
            streamWriter.WriteLine("//--------------------------");
            streamWriter.WriteLine("");

            foreach (KeyValuePair<string, string> parRegras in regrasGenInuteis)
            {
                streamWriter.WriteLine(parRegras.Key);
                streamWriter.WriteLine(parRegras.Value);
                streamWriter.WriteLine();
            }

            streamWriter.WriteLine("");
            streamWriter.WriteLine("");

            streamWriter.WriteLine("Regras Generalizadas Com Baixa Confiança");
            streamWriter.WriteLine("//--------------------------------------");
            streamWriter.WriteLine("");

            foreach (KeyValuePair<string, string> parRegras in regrasGenConfBaixa)
            {
                streamWriter.WriteLine(parRegras.Key);
                streamWriter.WriteLine(parRegras.Value);
                streamWriter.WriteLine();
            }

            streamWriter.WriteLine("");
            streamWriter.WriteLine("");

            streamWriter.WriteLine("Regras Generalizadas Em Coluna Realmente Úteis");
            streamWriter.WriteLine("//--------------------------------------------");
            streamWriter.WriteLine("");

            foreach (KeyValuePair<string, string> parRegras in regrasGenRealmenteUteis)
            {
                streamWriter.WriteLine(parRegras.Key);
                streamWriter.WriteLine(parRegras.Value);
                streamWriter.WriteLine();
            }

            streamWriter.Close();
        }
    }
}
